#include "Model.h"


Model::Model(string name,MeshPtr mesh,ModelInfoPtr s,RenderMode m)
	:RenderObject(COMP_MODEL,name,mesh,m),
	Resource(name),
	m_modelInfo(s),
	m_mesh(mesh)
{
	InitModel();
}


Model::~Model(void)
{
}

void Model::AddedToObject()
{
	RenderObject::AddedToObject();
}

void Model::InitModel()
{
	
	m_anim=boost::make_shared<Animation>(m_mesh->GetAnimData(),Animation::LINER_INTERPOLATION);
	m_worldMatrix=XMMatrixTranslation(m_modelInfo->pos.x,m_modelInfo->pos.y,m_modelInfo->pos.z);
	m_anim->SetSpeed(m_modelInfo->speed);
	CalcAnim(0);
}

void Model::CalcAnim(const int incr)
{
	if(m_mesh->GetMeshUsage()!=MESH_ANIM)
		return;
	Bones* tmpBones=new Bones;
	m_anim->CalcAnim(incr,tmpBones);
	m_mesh->CalcAnim(tmpBones);
	delete tmpBones;
}

XMMATRIX Model::GetWorldMatrix()
{

	return m_worldMatrix;
}